#include "nr_client_floorScada.h"
#include "ui_nr_client_floorScada.h"

subwindow2::subwindow2(QWidget *parent, Qt::WFlags flags)
	: QWidget(parent, flags)
{
	ui = new Ui::subwindow2;
	ui->setupUi(this);

	
	ui->imagelabel->setPixmap(QPixmap("floor5.png"));

	QPalette palette;
	palette.setBrush(QPalette::Background, QBrush(QPixmap("systemhomepage.png")));
	this->setPalette(palette);

	
// 	QPixmap pixmap("floor5.png");
// 	ui->imagelabel->setPixmap(pixmap);
// 	ui->imagelabel->show();

}

subwindow2::~subwindow2()
{
	delete ui;
}

void subwindow2::set_device_TreeWidgetItem( DeviceTreeWidgetItem &_device_TreeWidgetItem )
{
	m_device_TreeWidgetItem=&_device_TreeWidgetItem;
}

void subwindow2::set_device_type_manager( nr_device_type_manager &_device_type_manager )
{
	m_device_type_manager=&_device_type_manager;
	QStringList str_list;
	foreach( nr_device_type* devicetype, m_device_type_manager->device_types() )
	{
		str_list << devicetype->text();
	}
	//ui->comboBox->addItems( str_list );
}

void subwindow2::set_DataCommunication(client_Communication& clientdeviceTree)//translate data to subwindow2;
{
	m_clientdeviceTree = &clientdeviceTree;

	nr_device_item* deviceitem = (nr_device_item*)m_device_TreeWidgetItem->object_device();

	QList<nr_device_id_t> device_id_list;
	device_id_list.push_back( deviceitem->id() );
	m_clientdeviceTree->start_GetdataFromServer(device_id_list);

	connect(m_clientdeviceTree,SIGNAL(client_received_data(nr_data* )),this,SLOT(on_viewElectricEnergy(nr_data* )));
}

void subwindow2::on_viewElectricEnergy(nr_data* data)
{
	for(QVariantHash::iterator it = data->args().begin() ;it!=data->args().end(); ++it)
	{
		if (it.key() == "Ucn")
		{
			ui->lcdEE_1->display(it.value().toDouble());
		}
	}
}